package cn.hs.ph.dao.impl;

import cn.hs.ph.dao.UserDao;
import cn.hs.ph.entity.User;
import cn.hs.ph.util.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public User selectByUsernameAndPwd(String username, String pwd) {
        String sql = "select * from user where username=? and pwd=?";
        Object obj[]={username,pwd};
        User user = null;
        ResultSet res = JDBCDruidUtil.query(sql, obj);
        try {
            if (res.next()){
                user=new User(res.getInt(1),
                        res.getString(2),
                        res.getString(3));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        JDBCDruidUtil.close();
        return user;
    }
}
